package io.gitee.dqcer.mcdull.uac.provider.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import io.gitee.dqcer.mcdull.uac.provider.system.domain.CarOrder;
import io.gitee.dqcer.mcdull.uac.provider.system.domain.CarVehicle;
import io.gitee.dqcer.mcdull.uac.provider.system.domain.vo.CarOrderVO;
import io.gitee.dqcer.mcdull.uac.provider.system.domain.vo.CarVehicleVO;
import io.gitee.dqcer.mcdull.uac.provider.system.mapper.CarOrderMapper;
import io.gitee.dqcer.mcdull.uac.provider.system.mapper.SysUserMapper;
import io.gitee.dqcer.mcdull.uac.provider.system.service.ICarOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 订单管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-10
 */
@Service
public class CarOrderServiceImpl implements ICarOrderService
{
    @Autowired
    private CarOrderMapper carOrderMapper;

    @Resource
    private SysUserMapper sysUserMapper;

    /**
     * 查询订单管理
     * 
     * @param orderId 订单管理主键
     * @return 订单管理
     */
    @Override
    public CarOrder selectCarOrderByOrderId(Long orderId)
    {
        return carOrderMapper.selectCarOrderByOrderId(orderId);
    }

    /**
     * 查询订单管理列表
     * 
     * @param carOrder 订单管理
     * @return 订单管理
     */
    @Override
    public List<CarOrderVO> selectCarOrderList(CarOrder carOrder)
    {

        List<CarOrderVO> voList = new ArrayList<>();
        List<CarOrder> list = carOrderMapper.selectCarOrderList(carOrder);
        for (CarOrder order : list) {
            CarOrderVO vo = this.convertVO(order);
            vo.setNickName(sysUserMapper.selectUserById(vo.getUserId()).getNickName());
            voList.add(vo);
        }
        return voList;
    }

    private CarOrderVO convertVO(CarOrder order) {
        CarOrderVO carOrderVO = new CarOrderVO();
        carOrderVO.setOrderId(order.getOrderId());
        carOrderVO.setUserId(order.getUserId());
        carOrderVO.setServiceType(order.getServiceType());
        carOrderVO.setOrderStatus(order.getOrderStatus());
        carOrderVO.setCreatedAt(order.getCreatedAt());
        carOrderVO.setCompletedAt(order.getCompletedAt());
        carOrderVO.setPaidAt(order.getPaidAt());
        carOrderVO.setCancelledAt(order.getCancelledAt());
        carOrderVO.setTotalAmount(order.getTotalAmount());
        carOrderVO.setPaymentMethod(order.getPaymentMethod());
        carOrderVO.setNotes(order.getNotes());
        carOrderVO.setUpdatedAt(order.getUpdatedAt());
        carOrderVO.setSearchValue(order.getSearchValue());
        carOrderVO.setCreateBy(order.getCreateBy());
        carOrderVO.setCreateTime(order.getCreateTime());
        carOrderVO.setUpdateBy(order.getUpdateBy());
        carOrderVO.setUpdateTime(order.getUpdateTime());
        carOrderVO.setRemark(order.getRemark());
        carOrderVO.setParams(order.getParams());
        return carOrderVO;
    }

    /**
     * 新增订单管理
     * 
     * @param carOrder 订单管理
     * @return 结果
     */
    @Override
    public int insertCarOrder(CarOrder carOrder)
    {
        return carOrderMapper.insertCarOrder(carOrder);
    }

    /**
     * 修改订单管理
     * 
     * @param carOrder 订单管理
     * @return 结果
     */
    @Override
    public int updateCarOrder(CarOrder carOrder)
    {
        return carOrderMapper.updateCarOrder(carOrder);
    }

    /**
     * 批量删除订单管理
     * 
     * @param orderIds 需要删除的订单管理主键
     * @return 结果
     */
    @Override
    public int deleteCarOrderByOrderIds(Long[] orderIds)
    {
        return carOrderMapper.deleteCarOrderByOrderIds(orderIds);
    }

    /**
     * 删除订单管理信息
     * 
     * @param orderId 订单管理主键
     * @return 结果
     */
    @Override
    public int deleteCarOrderByOrderId(Long orderId)
    {
        return carOrderMapper.deleteCarOrderByOrderId(orderId);
    }
}
